
// 获取新时间
exports.getNowDate = ()=>{
    let nowDate = new Date();
    let y = nowDate.getFullYear();
    let m = nowDate.getMonth()+1;
    let d = nowDate.getDate();
    if(m<10) m = "0" + m;
    if(d<10) d = "0" + d;
    let hh = nowDate.getHours();
    let mm = nowDate.getMinutes();
    let ss = nowDate.getSeconds();
    if(hh<10) hh = "0" + hh;
    if(mm<10) mm = "0" + mm;
    if(ss<10) ss = "0" + ss;
    return y + "-" + m + "-" + d + " " + hh + ":" + mm + ":" + ss;
}

// 将日期转换 2022-12-5   ===>   2022-12-05
exports.toDateYMD = (date)=>{
    let arr = date.split("-");
    if(arr[1]<10) arr[1] = "0" + arr[1];
    if(arr[2]<10) arr[2] = "0" + arr[2];
    return arr.join("-");
}

// 将节日转换为MM-DD
exports.toDateMD = (date)=>{
    let arr = date.split("-");
    if(arr[0]==''||arr[1]=='')return null;
    try {
        if(arr[0].indexOf('0')&&arr[0]<10) arr[0] = "0" + arr[0];
        if(arr[1].indexOf('0')&&arr[1]<10) arr[1] = "0" + arr[1];
        return arr.join("-");
    } catch (e) {
        return null;
    }
}

// 将时间转换，补零
exports.toTimeHHMMSS = (time)=>{
    let arr = time.split(":");
    arr.forEach(item => {
        if(item<10) item = "0" + item;
    });
    return arr.join(":");
}
